var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
// 404错误件
app.use((req,res,next)=>{
res.json( {code:404,datmull,msg:"路由不匹配"})
})

// 逻辑错误
app.use((err,erq,res)=>{
    res.json({code:201,date:mnull,msg:"警告"+ err})
})

module.exports = app;
